package com.xtm.exercise.lock;

import com.xtm.common.controller.ResultController;
import com.xtm.common.model.Result;
import com.xtm.exercise.lock.base.ILockService;
import com.xtm.utils.bool.BooleanUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 加锁业务 - 控制层 - 用于演示 锁 的使用<p/>
 */
@ResultController
@RequiredArgsConstructor
@Api(value = "加锁业务", tags = "演示示例")
public class LockController {

    private final ILockService lockService;

    /**
     * 加锁业务
     */
    @PutMapping("/locks")
    @ApiOperation(value = "加锁业务")
    public Result<?> test (@RequestBody MenuParam param) {
        boolean imitateException = BooleanUtils.bool(param.isImitateException(), false);
        lockService.test(param.getId(), param.getSleepSeconds(), imitateException);
        return Result.ok();
    }

}
